//
//  KDLibrary.h
//  Amber
//
//  Created by Keith Duncan on 05/03/2008.
//  Copyright 2008 thirty-three. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@class AFLibrary, AFSourceNode;

/*!
	@const
 */
extern NSString *const AFLibraryUnknownLocation;

/*!
	@function
 */
NS_INLINE BOOL AFFileExistsAtPath(NSString *path) {
	return (path != nil && ![path isEmpty] && [[NSFileManager defaultManager] fileExistsAtPath:[path stringByExpandingTildeInPath]]);
}

/*!
	@protocol
 */
@protocol AFLibraryDelegate <AFBundleDiscovery>

/*!
	@method
 */
- (void)requestPathForLibrary:(AFLibrary *)library;

 @optional

/*!
	@method
	@abstract	Root children are NEVER selectable and you won't be queried
 */
- (BOOL)library:(AFLibrary *)library isObjectSelectable:(id)object;

@end

/*!
    @class
    @abstract    This is an abstract class for loading XML library representations, iTunes initially, perhaps iPhoto or another custom store
*/
@interface AFLibrary : NSObject {
	id <AFLibraryDelegate> delegate;
	
	BOOL _loaded;
	
	id _library;
	NSString *_path;
	
	AFSourceNode *_rootNode;
}

/*!
	@method
	@abstract	Designated Initialiser.
	@param		|path| pass AFLibraryUnknownLocation to trigger an immediate request
 */
- (id)initWithFilePath:(NSString *)path;

/*!
	@property
 */
@property (copy) NSString *path;

/*!
	@property
 */
@property (assign) id <AFLibraryDelegate> delegate;

- (BOOL)isLoaded;

/*!
	@method
 */
- (BOOL)loadAndReturnError:(NSError **)error;

/*!
	@method
 */
@property (retain, readonly) AFSourceNode *rootNode;

/*!
	@method
	@abstract	This should really be a subclass specific function...
 */
- (NSMenu *)sourceMenu;

@end

/*!
	@protocol
	@abstract	Library subclasses MUST conform to this protocol
 */
@protocol AFLibraryDiscovery <NSObject>
- (NSString *)name;
- (NSString *)expectedPath;
 @optional
- (NSArray *)additionalSearchPaths;
@end
